﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QWeiBo.ViewModel;
using TencentWeiboSDK.Services;
using System.Threading;
using TencentWeiboSDK.Services.Util;

namespace QWeiBoN.ViewModule
{
    public class AddFriendModel : BaseViewModel
    {
        /// <summary>
        /// 实例化朋友服务类
        /// </summary>
        private FriendsService friendService = new FriendsService();

        /// <summary>
        /// 用于取消收听fans
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="action"></param>
        public void delFriend(string openId, Action<Callback<Object>> action)
        {
            // 为了增加用户体验，使用异步操作
            new Thread(() =>
            {
                Action<Callback<Object>> action1 = new Action<Callback<object>>((callBack) =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (null == callBack.InnerException)
                        {
                            MessageBox.Show("取消收听成功");
                        }
                        else
                        {
                            MessageBox.Show(callBack.InnerException.Message);
                        }
                    });

                    if (null != action)
                    {
                        action(callBack);
                    }
                });

                // 取消收听
                friendService.Del(new ServiceArgument() { FOpenId = openId }, action1);

            }).Start();
        }

        /// <summary>
        /// 用于收听新的fans
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="action"></param>
        public void addFriend(string openId, Action<Callback<Object>> action)
        {
            // 为了增加用户体验，使用异步操作
            new Thread(() =>
            {
                Action<Callback<Object>> action1 = new Action<Callback<object>>((callBack) =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (null == callBack.InnerException)
                        {
                            MessageBox.Show("收听成功");
                        }
                        else
                        {
                            MessageBox.Show(callBack.InnerException.Message);
                        }
                    });

                    if (null != action)
                    {
                        action(callBack);
                    }
                });

                // 添加新的
                friendService.Add(new ServiceArgument() { FOpenIds = openId }, action1);

            }).Start();
        }
    }
}
